$(function () {
    // alert('aa');

    // 获取'我要借款'页面传入的 type
    let type = location.search.split('=')[1];
    // console.log(type);

    // 判断 type 的值
    switch (type) {
        case '1':
            $('.borrow_type span').html('信用贷');
            break;

        case '2':
            $('.borrow_type span').html('车易贷');
            break;

        case '3':
            $('.borrow_type span').html('房易贷');
            break;
    }

    $('.apply_btn').click(function () {
        // alert('确认')

        let userid = sessionStorage.getItem('id');
        let borrowType = type;
        let borrowmoney = $('.borrowmoney input').val();
        let interest = $('.interest input').val();
        let borrowtime = $('.borrowtime option:selected').val();
        let repaytype = $('.repaytype input:checked').val();
        let minbid = $('.minbid input').val();
        let bouns = $('.bouns input').val();
        let days = $('.days option:selected').val();
        let title = $('.title input').val();
        let info = $('.info textarea').val();
        // console.log(info);

        $.ajax({
            url: 'http://139.9.177.51:3333/p2p/borrow',
            type: 'POST',
            data: {
                userid,
                borrowType,
                borrowmoney,
                interest,
                borrowtime,
                repaytype,
                minbid,
                bouns,
                days,
                title,
                info
            },
            success: function (res) {
                console.log(res);
                
                if (res.code == 200) {
                    alert('申请成功!');
                    location.href = '/';
                } else {
                    alert('申请失败~');
                }
            }
        })
        
    })

})